home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
fish
/
001-100
/
001-025
/
004
/
bm
/
search.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-17
|
980b
|
41 lines
#include "bm.h"
#include "Extern.h"
int Search(Pattern,PatLen,Buffer, EndBuff, Skip1, Skip2, Desc)
char Pattern[];
int PatLen;
char Buffer[];
char *EndBuff;
int Skip1[], Skip2[];
struct PattDesc *Desc;
{
register char *k, /* indexes text */
*j, /* indexes Pattern */
*PatBegin; /* register pointing to char
* before beginning of Pattern */
register int Skip; /* skip distance */
char *PatEnd,
*BuffEnd; /* pointers to last char in Pattern and Buffer */
BuffEnd = EndBuff;
PatBegin = Pattern - 1;
PatEnd = Pattern + PatLen - 1;
k = Desc->Start;
Skip = PatLen-1;
while ( Skip <= (BuffEnd - k) ) {
j = PatEnd;
k = k + Skip;
while (j > PatBegin && *j == *k) {
--j; --k;
} /* while */
if (j< Pattern) {
/* found it. Start next search
* just after the pattern */
Desc -> Start = k + 1 + Desc->PatLen;
return(1);
} /* if */
Skip = max(Skip1[*(unsigned char *)k],Skip2[j-Pattern]);
} /* while */
Desc->Start = k;
return(0);
} /* Search */